[PATCH] QTextMarkdownImporter: Fix heap-buffer-overflow
authorShawn Rutledge <shawn.rutledge@qt.io>
Thu, 27 Mar 2025 14:17:21 +0000 (15:17 +0100)
committerPatrick Franz <deltaone@debian.org>
Tue, 2 Sep 2025 19:04:45 +0000 (21:04 +0200)
commit3922d0a92ec8abdd978290e9cca1b4e5c4db7b62
tree5af40f4a5ccfc3c52bda42852bc6f75012d95b62
parentadf6f7613b30ca575b7c23631487be1850aa1d91
[PATCH] QTextMarkdownImporter: Fix heap-buffer-overflow

After finding the end marker `---`, the code expected more characters
beyond: typically at least a trailing newline. But QStringView::sliced()
crashes if asked for a substring that starts at or beyond the end.

Now it's restructured into a separate splitFrontMatter() function, and
we're stricter, tolerating only `---\n` or `---\r\n` as marker lines.
So the code is easier to prove correct, and we don't need to check
characters between the end of the marker and the end of the line
(to allow inadvertent whitespace, for example). If the markers are
not valid, the Markdown parser will see them as thematic breaks,
as it would have done if we were not extracting the Front Matter
beforehand.

Amends e10c9b5c0f8f194a79ce12dcf9b6b5cb19976942 and
bffddc6a993c4b6b64922e8d327bdf32e0d4975a

Credit to OSS-Fuzz which found this as issue 42533775.

[ChangeLog][QtGui][Text] Fixed a heap buffer overflow in
QTextMarkdownImporter. The first marker for Front Matter
must begin at the first character of a Markdown document,
and both markers must be exactly ---\n or ---\r\n.

Done-with: Marc Mutz <marc.mutz@qt.io>
Fixes: QTBUG-135284
Change-Id: I66412d21ecc0c4eabde443d70865ed2abad86d89
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 25986746947798e1a22d0830d3bcb11a55fcd3ae)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit eced22d7250fc7ba4dbafa1694bf149c2259d9ea)
(cherry picked from commit 9e59a924a04606c386b970ee6c9c7819cdd7ae1a)

Gbp-Pq: Name upstream_cve-2025-3512_fix_heap_buffer_overflow.diff
src/gui/text/qtextmarkdownimporter.cpp
tests/auto/gui/text/qtextmarkdownimporter/data/front-marker-malformed1.md [new file with mode: 0644]
tests/auto/gui/text/qtextmarkdownimporter/data/front-marker-malformed2.md [new file with mode: 0644]
tests/auto/gui/text/qtextmarkdownimporter/data/front-marker-malformed3.md [new file with mode: 0644]
tests/auto/gui/text/qtextmarkdownimporter/data/oss-fuzz-42533775.md [new file with mode: 0644]
tests/auto/gui/text/qtextmarkdownimporter/data/yaml-crlf.md [new file with mode: 0644]
tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp